home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / paint.h < prev    next >
C/C++ Source or Header  |  1994-11-19  |  3KB  |  99 lines

  1. #ifndef __PAINT_H_
  2. #define __PAINT_H_
  3.  
  4. /*  Platform and drawing library (in theory) independent drawing tools.
  5.     Basic drawing primitives, rotation, mirror reflection, complex rotation,
  6.     zooming and scrolling.
  7. */
  8.  
  9. #include <math.h>
  10. #include "geom.h"
  11. #include "bgi_font.h"
  12. #include "trigon.h"
  13.  
  14. #define R_STEP 20
  15. /*   Rotation could be simply processed if it is single operation. To use
  16.      nested rotations we use stack of rotations info structures. Example of
  17.      complex rotation:
  18.      void f1(int x, int y, int alpha) { ... perform rotation ... }
  19.      void f2(int x, int y, int alpha) { rotate(10,10,90); f1(x, y, alpha); }
  20.      Function f2() call rotation procedure and then call f1(), which call
  21.      another rotation. We could a) cancel first rotation and b) add first
  22.      and second rotations to complex transformation.
  23. */
  24.  
  25. struct RInfo
  26.     {
  27.     loc center;
  28.     int angle;
  29.     };
  30. ///////////////
  31. struct Stack
  32.     {
  33.     int used, total;
  34.     RInfo* list;
  35.  
  36.     Stack();
  37.     ~Stack();
  38.     void push(RInfo* r);
  39.     void pop();
  40.     void flash();
  41.     };
  42.  
  43. ///////////////
  44. /*      Some additional facilities for any graphics library. Class
  45.     functions may be overloaded for adaptation to concrete graphic
  46.     interface (BGI, GDI, and so on).
  47.     Functions could set error code in kh_error_code variable.
  48.     The zoom and addzoom are deformation coeficients. You could
  49.     use zoom in any part of program. Addzoom is used only once to
  50.     set the additional deformation of the whole picture (for example
  51.     if context is changed from screen to printer), for preview and so on.
  52. */
  53.  
  54. class Paint : public BGI_Font, public Trigonometry
  55.     {
  56.     protected:
  57.     loc zoom;                     // Image deformation
  58.     loc add_zoom;                 // Additional deformation
  59.     loc lt;                       // Scroll of part of picture
  60.     loc add_scroll;               // Left - top clip of the whole picture
  61.     int fill;                     // Fill flag
  62.     int mirror;
  63.     public:
  64.     loc center;                   // Rotation center
  65.     int alpha;                    // Rotation angle
  66.     bool R_STACK;                 // Use or not stack of rotations
  67.     Stack* r_stack;               // Stack of rotations
  68.  
  69.     Paint();
  70.     ~Paint() { delete r_stack; }
  71.  
  72.     loc get_add_zoom() { return add_zoom; }
  73.     loc get_zoom() { return zoom; }
  74.  
  75.     void set_mirror(int m) { mirror = m; } // X coord. if no rotation
  76.     void set_stack(bool r) { R_STACK = r; r_stack->flash();
  77.         rotate(loc(0, 0), 0); }
  78.     void set_stack_soft(bool r) { R_STACK = r; }
  79.     void set_zoom(double x, double y) { zoom.X = x * add_zoom.X;
  80.         zoom.Y = y * add_zoom.Y; }    // No out-of-range control !!!
  81.     void set_add_zoom(double x, double y) { add_zoom.X = 100 * x;
  82.         add_zoom.Y = 100 * y; }
  83.     void set_scroll(int x, int y) { lt.X = x; lt.Y = y; }
  84.     void set_add_scroll(int x, int y) { add_scroll.X = x;
  85.         add_scroll.Y = y; }
  86.     void rotate(loc c, int a);
  87.     void rotate(int x, int y, int alpha) { rotate(loc(x, y), alpha); }
  88.     void set_fill(bool f) { fill = f; }
  89.  
  90. // Using alpha and center returns rotated coordinates
  91.     loc rot(int x, int y);
  92. // Return completely transformed point: rotated, zoomed and scrolled
  93.     loc transform(int x, int y);
  94.     };
  95.  
  96.  
  97. #endif __PAINT_H_
  98.  
  99.